
#include "Reactor.hpp"
#include "Listen.hpp"

#include "calcualtor.hpp"
#include "Expressed.hpp"


int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        cout << "ServerMain serverport" << endl;
        return 1;
    }
    uint16_t port = stoi(argv[1]);
    Reactor reactor;//会话层

    Calculator cal;//计算器--应用层

    Expressed expressed;//表示层

    expressed.Registration([&cal](const int left,const char oper,const int right,int& result)
    {
        return cal.Calculate(left,oper,right,result);
    });

    shared_ptr<Connection> listensocket = make_shared<Listener>(&reactor,port);
    reactor.InsetConnection(listensocket->Fd(), listensocket);

    reactor.Register([&expressed](string &readbuff)
    {
        return expressed.HandleRequest(readbuff);
    });

    reactor.Start();

    return 0;
}